import { EditorController, FormItemController } from '@ibiz-template/runtime';
import { IEditor } from '@ibiz/model-core';

export class GroupShiftsController extends EditorController<IEditor> {
  /**
   * 加载班次
   *
   * @return {*}
   * @memberof GroupShiftsController
   */
  async loadShifts(): Promise<IData[]> {
    const shiftService = await ibiz.hub.getAppDEService(
      this.context.srfappid,
      'attendanceapp.attendance_shift',
      this.context,
    );
    const result = await shiftService.local.getList();
    return result;
  }

  /**
   * 加载所有排班数据
   *
   * @return {*}
   * @memberof GroupShiftsController
   */
  async loadAllWorkDays(): Promise<IData[]> {
    const groupShiftService = await ibiz.hub.getAppDEService(
      this.context.srfappid,
      'attendanceapp.attendance_group_shift',
      this.context,
    );
    const result = await groupShiftService.local.getList();
    return result;
  }

  /**
   * 获取大表单数据
   *
   * @return {*}  {(IData | null | undefined)}
   * @memberof GroupShiftsController
   */
  public getBigFormData(): IData | null | undefined {
    const viewController = (this.parent as FormItemController).form.view;
    if (viewController && viewController.getController('form')) {
      const form = viewController.getController('form');
      return (form?.state as IData).data;
    }
  }
}
